// pages/reviewRecord/playReport/playReport.js
const app = getApp();
const httpUtils = require('../../../utils/httpUtils.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageName: '复习报告',
    navH: app.globalData.navHeight,
    windowHeight: 0,
    imageUrl: "https://yxpmaterial.oss-cn-beijing.aliyuncs.com/",
    minutes: parseInt(app.globalData.taskTwoMinuts / 60),
    reportData: {},
    date: '', //学习日期
    isContinueDisabled: false, //继续闯关按钮是否可用
    task_id: "",
    sort: "",
    type: 0, //复习类型 0 单词 1 阅读 3 语法 4 写作
    can_submit: 1, //1 可以提交 0不可以提交
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.getSystemInfo({
      success: res => {
        this.data.windowHeight = res.windowHeight - this.data.navH,
          this.data.windowWidth = res.windowWidth
      },
      fail(err) {
        console.log(err);
      }
    })
    that.setData({
      windowHeight: this.data.windowHeight,
      task_id: options.task_id,
      sort: options.sort,
      type: options.type,
      can_submit: options.can_submit,
      date: options.date
    })

    that.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    console.log("onShow()---cansubmit=" + that.data.can_submit)
    if (that.data.reportData.remain <= 0 || that.data.can_submit == 0) {
      that.setData({
        isContinueDisabled: true
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //获取报告数据
  getData: function () {
    let that = this;
    wx.showLoading({
      title: '',
      mask: true
    })
    httpUtils.getWorkReport({
      access_token: app.globalData.studentInfo.access_token ? app.globalData.studentInfo.access_token : app.globalData.access_token,
      calendar_id: that.data.task_id,
      sort: that.data.sort,
      type: that.data.type

    }).then((res) => {
      wx.hideLoading();
      that.setData({
        reportData: res.data,
      })
      if (that.data.reportData.remain <= 0 || that.data.can_submit == 0) {
        that.setData({
          isContinueDisabled: true
        })
      }
    });


  },

  // 查看错词
  goWrong: function () {
    let that = this;
    if (this.data.reportData.err == 0) {
      wx.showToast({
        title: '暂无错词哦',
        icon: 'none'
      })
      return;
    }
    wx.navigateTo({
      url: '../lwordWrong/lwordWrong?sort=' + that.data.sort + "&task_id=" + that.data.task_id,
    })
  },
  goPlay: function () {
    let that = this;
    let sort = that.data.sort;
    console.log("继续闯关，sort=" + sort)
    if (sort == 0) {
      wx.redirectTo({ //学后检测
        url: '/pages/testReport/testReport?sort=' + sort + "&task_id=" + that.data.task_id + "&can_submit=" + that.data.can_submit + "&date=" + that.data.date,
      })
    } else if (sort == 1) { //词义闯关
      wx.redirectTo({
        url: '/pages/reviewRecord/worldMean/worldMean?sort=' + sort + "&task_id=" + that.data.task_id + "&can_submit=" + that.data.can_submit + "&date=" + that.data.date,
      })
    } else if (sort == 2) {  //对对碰
      wx.redirectTo({
        url: '/pages/reviewRecord/takesTwo/takesTwo?sort=' + sort + "&task_id=" + that.data.task_id+"&can_submit="+that.data.can_submit +"&date=" + that.data.date,
      })

    } else if (sort == 3) { //听音识义
      wx.redirectTo({
        url: '/pages/reviewRecord/listenWorld/listenWorld?sort=' + sort + "&task_id=" + that.data.task_id+"&can_submit="+that.data.can_submit +"&date=" + that.data.date,
      })

    } else if (sort == 4) {  //组合拼
      wx.redirectTo({
        url: '/pages/reviewRecord/spellword/spellWord?sort=' + sort + "&task_id=" +that.data.task_id+"&can_submit="+that.data.can_submit+"&date=" + that.data.date,
      })
    }
  },
})